// 练习一

const fp = require("lodash/fp");
const { Maybe, Container } = require("./support");

let maybe = Maybe.of([5, 6, 1]);
let ex1 = (y) =>
  maybe.map((x) => {
    return fp.map(fp.add(y), x);
  });

console.log(ex1(4));

// 练习二

let xs = Container.of(["do", "ray", "me", "fa", "so", "la", "ti", "do"]);

let ex2 = xs.map((x) => fp.first(x));
console.log(ex2);

//练习三

let safeProp = fp.curry(function (x, o) {
  return Maybe.of(o[x]);
});

let user = { id: 2, name: "Albert" };

let ex3 = fp.flowRight(
  fp.map((x) => fp.first(x)),
  safeProp("name")
);
console.log(ex3(user));

//练习四
let ex4 = function (n) {
  //   if (n) {
  //     return parseInt(n);
  //   }
  return Maybe.of(n).map((n) => parseInt(n));
};

console.log(ex4(7.5));
